//
//  BKODAliManager.m
//  bestkeep
//
//  Created by 马乾征 on 16/12/12.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKODAliManager.h"
#import "BKOrderPayForResultsViewController.h"

@implementation BKODAliManager

- (instancetype)initPrivate
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

+ (instancetype)manager
{
    static BKODAliManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[BKODAliManager alloc] initPrivate];
    });
    return manager;
}

- (void)payRequestOrderString:(NSString *)order
{
    __weak typeof(self)weakSelf = self;
    
    [[AlipaySDK defaultService] payOrder:order fromScheme:@"bestkeep" callback:^(NSDictionary *resultDic) {
        
        if (weakSelf.delegate && [weakSelf.delegate conformsToProtocol:@protocol(BKODAliManagerDelegate)]) {
            [weakSelf.delegate ODWAliManagerDidRecvPayResult:resultDic];
        }
    }];
}

- (void)paymentResultWithOpenUrl:(NSURL *)url
{

    if ([url.host isEqualToString:@"safepay"])
    {
        __weak typeof(self)weakSelf = self;
        
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic)
         {
             if (weakSelf.delegate && [weakSelf.delegate conformsToProtocol:@protocol(BKODAliManagerDelegate)])
             {
                 [weakSelf.delegate ODWAliManagerDidRecvPayResult:resultDic];
             }
         }];
    }
}

@end
